----------------------------------------------------------------
-- File   : ~/.xmonad/xmonad.hs                               --
-- Author : Digit                                             --
-- Desc   : Digit's XMonad config for triple vertical monitor --
-- Version: dripple051-mouseresizeabletile-in-themix          --  work in progress
----------------------------------------------------------------

import XMonad
import XMonad hiding ((|||))

import XMonad.Layout -- trying to get rid of not-in-scope errors after adding original binds
import XMonad.StackSet as W -- still trying, but getting different errors now

import XMonad.Layout.Tabbed
import XMonad.Layout.Combo --meh? see sublayouts
import XMonad.Layout.SubLayouts
import XMonad.Layout.WindowNavigation --sublayouts
import XMonad.Layout.BoringWindows --sublayouts
import XMonad.Layout.MouseResizableTile
import XMonad.Layout.Grid
import XMonad.Layout.TwoPane
import XMonad.Util.CustomKeys
import XMonad.Layout.LayoutCombinators hiding ((|||))
import XMonad.Actions.CycleSelectedLayouts -- y u no work yet?

--layoutsets
digitstripleLayout = windowNavigation $ subTabbed $ boringWindows $
		       Grid ||| TwoPane (3/100) (1/2) ||| Full ||| (Tall 1 (3/100) (1/2) *//* Full)  ||| (Tall 1 (3/100) (1/2) ***||** Full) ||| simpleTabbed -- more to come

fidjitstripleLayout = windowNavigation $ subTabbed $ boringWindows $  
                        (Grid ***||** simpleTabbed) ||| (Grid *//* simpleTabbed) ||| (simpleTabbed ***||** Grid) ||| (simpleTabbed *//* Grid)
                        
smidjitstripleLayout = windowNavigation $ subTabbed $ boringWindows $  
                        (Grid *//* simpleTabbed) ||| (simpleTabbed *//* Grid) ||| (Grid *//* simpleTabbed) ||| (simpleTabbed ***||** Grid)

jijitstripleLayout = windowNavigation $ subTabbed $ boringWindows $  
                       mouseResizableTile ||| (mouseResizableTile *//* Grid) ||| (Grid *//* mouseResizableTile) ||| Full

-- next layout to add: http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Layout-ResizableTile.html


main = xmonad defaultConfig
        { layoutHook	= jijitstripleLayout -- pick a layoutset, any layouset^
	, modMask	= mod4Mask
	, keys		= customKeys delkeys inskeys
	}
     where
       delkeys :: XConfig l -> [(KeyMask, KeySym)]
       delkeys XConfig {modMask = modm} =
           -- we're preferring Futurama to Xinerama here
         --jank?
           [(modm .|. m, k) | (m, k) <- zip [0, shiftMask] [xK_x, xK_c, xK_v] ]

--           [((m .|. modm, key), screenWorkspace sc >>= flip whenJust (windows . f))
--               | (key, sc) <- zip [xK_x, xK_c, xK_v] [0..]
--               , (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]

       inskeys :: XConfig l -> [((KeyMask, KeySym), X ())]
       inskeys conf@(XConfig {modMask = modm}) =
           [ ((mod1Mask,             xK_F2  ), spawn $ terminal conf)
           , ((modm .|. controlMask, xK_F11 ), spawn "xscreensaver-command -lock")
           , ((mod1Mask,             xK_Down), spawn "amixer set Master 1-")
           , ((mod1Mask,             xK_Up  ), spawn "amixer set Master 1+")
           , ((modm .|. controlMask .|. shiftMask, xK_f), sendMessage $ Move R)  -- ?
	   , ((modm .|. controlMask .|. shiftMask, xK_s), sendMessage $ Move L)  -- ?
	   , ((modm .|. controlMask .|. shiftMask, xK_e), sendMessage $ Move U)  -- ?
	   , ((modm .|. controlMask .|. shiftMask, xK_d), sendMessage $ Move D)  -- ?      
           , ((modm .|. controlMask .|. shiftMask, xK_Right), sendMessage $ Move R)  -- ?
	   , ((modm .|. controlMask .|. shiftMask, xK_Left ), sendMessage $ Move L)  -- ?
	   , ((modm .|. controlMask .|. shiftMask, xK_Up   ), sendMessage $ Move U)  -- ?
	   , ((modm .|. controlMask .|. shiftMask, xK_Down ), sendMessage $ Move D)  -- ?
	   , ((modm, xK_z), sendMessage ShrinkSlave) -- %! Shrink a slave area
	   , ((modm, xK_b), sendMessage ExpandSlave) -- %! Expand a slave area
	   , ((modm .|. controlMask, xK_s), sendMessage $ pullGroup L)
	   , ((modm .|. controlMask, xK_f), sendMessage $ pullGroup R)
	   , ((modm .|. controlMask, xK_e), sendMessage $ pullGroup U)
	   , ((modm .|. controlMask, xK_d), sendMessage $ pullGroup D)

	   , ((modm, xK_a), withFocused (sendMessage . MergeAll))
	   , ((modm .|. controlMask, xK_a), withFocused (sendMessage . UnMerge))

--	   , ((modm .|. controlMask, xK_period), onGroup W.focusUp')
--	   , ((modm .|. controlMask, xK_comma), onGroup W.focusDown')
----	   , ((modm, xK_d), focusDown) -- new error when added http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Util-NamedScratchpad.html
----	   , ((modm, xK_e), focusUp) -- new error when added http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Util-NamedScratchpad.html

-- THE ORIGINALS (addapted)
           , ((modm .|. shiftMask, xK_Return), spawn $ XMonad.terminal conf) -- %! Launch terminal
           , ((modm, xK_r), spawn "dmenu_run") -- %! Launch dmenu
--           , ((modMask .|. shiftMask, xK_p     ), spawn "gmrun") -- %! Launch gmrun
           , ((modm .|. shiftMask, xK_w     ), kill) -- %! Close the focused window

           , ((modm, xK_BackSpace ), sendMessage NextLayout) -- %! Rotate through the available layout algorithms
--           , ((modm .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf) -- %!  Reset the layouts on the current workspace to default

           , ((modm, xK_n ), refresh) -- %! Resize viewed windows to the correct size

    -- move focus up or down the window stack
           , ((modm, xK_Tab ), windows W.focusDown) -- %! Move focus to the next window
           , ((modm .|. shiftMask, xK_Tab   ), windows W.focusUp  ) -- %! Move focus to the previous window
           , ((modm,               xK_d     ), windows W.focusDown) -- %! Move focus to the next window
           , ((modm,               xK_e     ), windows W.focusUp  ) -- %! Move focus to the previous window
           , ((modm,               xK_Agrave ), windows W.focusMaster  ) -- %! Move focus to the master window --grave, rly?

    -- modifying the window order
           , ((modm,  xK_a), windows W.swapMaster) -- %! Swap the focused window and the master window
           , ((modm .|. shiftMask, xK_e     ), windows W.swapDown  ) -- %! Swap the focused window with the next window
           , ((modm .|. shiftMask, xK_d     ), windows W.swapUp    ) -- %! Swap the focused window with the previous window

    -- resizing the master/slave ratio
           , ((modm .|. shiftMask, xK_z     ), sendMessage Shrink) -- %! Shrink the master area
           , ((modm .|. shiftMask, xK_b     ), sendMessage Expand) -- %! Expand the master area

    -- floating layer support
           , ((modm, xK_t ), withFocused $ windows . W.sink) -- %! Push window back into tiling

    -- increase or decrease number of windows in the master area
           , ((modm , xK_s ), sendMessage (IncMasterN 1)) -- %! Increment the number of windows in the master area
           , ((modm , xK_f ), sendMessage (IncMasterN (-1))) -- %! Deincrement the number of windows in the master area

    -- quit, or restart
--           , ((modm .|. shiftMask, xK_q     ), io (exitWith ExitSuccess)) -- %! Quit xmonad
           , ((modm              , xK_q     ), spawn "if type xmonad; then xmonad --recompile && xmonad --restart; else xmessage xmonad not in \\$PATH: \"$PATH\"; fi") -- %! Restart xmonad

--           , ((modm .|. shiftMask, xK_slash ), spawn ("echo \"" ++ help ++ "\" | xmessage -file -")) -- %! Run xmessage with a summary of the default keybindings (useful for beginners)
    -- repeat the binding for non-American layout keyboards
--           , ((modm              , xK_question), spawn ("echo \"" ++ help ++ "\" | xmessage -file -"))  
           , ((modm, xK_g ), cycleThroughLayouts ["Grid", "Full"]) --y u no work?
	   ]
           ++
           -- jank?
           [((m .|. modm, key), screenWorkspace sc >>= flip whenJust (windows . f))
               | (key, sc) <- zip [xK_x, xK_c, xK_v] [0..]
               , (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]           